There are conventional techniques for calculating the attitude of a device using a magnetic sensor. For example, by detecting the direction of a magnetic field using a magnetic sensor, it is possible to calculate the attitude of a device with respect to the direction of the magnetic field.
Where an attitude is calculated using a sensor, the ability to precisely calculate the attitude is required.
Thus, the present disclosure provides a storage medium having information processing program stored thereon, an information processing device, an information processing system, and an attitude calculation method capable of precisely calculating the attitude of a device.
(1)
This application describes a non-transitory computer-readable storage medium storing an information processing program to be executed by a computer of an information processing device for calculating an attitude of an input unit having a magnetic sensor. The information processing program causes the computer to execute the following.
The computer repeatedly obtains detected magnetic vectors detected by the magnetic sensor. The computer repeatedly estimates a center position of a spherical body having a curved surface which is estimated based on end point positions of the detected magnetic vectors. The computer calculates the attitude of the input unit based on a direction vector representing a direction from the center position to the end point position of the detected magnetic vector.
Each time a detected magnetic vector is obtained, the computer updates the center position so that at least some of lengths from the center position to end points of the detected magnetic vectors used for the estimation of the center position are brought closer to an average between the lengths.
With configuration (1) above, each time a detected magnetic vector is obtained, the center position is updated so that the lengths come close to being an equal length, and it is therefore possible to calculate an accurate center position based on the latest detected magnetic vector. Thus, it is possible to more precisely calculate the attitude of the input unit. Since the center position is updated each time a detected magnetic vector is obtained, it is possible to start the calculation of the center position even before obtaining a sufficiently large number of detected magnetic vectors, and it is possible to start the attitude calculation early.
(2)
In response to a predetermined condition satisfied by the detected magnetic vectors, the computer may estimate the center position based on the detected magnetic vectors.
With configuration (2) above, since the center position is estimated in response to satisfaction of a predetermined condition, it is possible to reduce the possibility that a center position is obtained that is so inaccurate that it cannot be used in the attitude calculation, and it is possible to more precisely calculate the attitude.
(3)
The predetermined condition may be that an area determined based on the end point positions of the detected magnetic vectors has become larger than a predetermined size.
With configuration (3) above, the center position is calculated when an area determined based on the end point positions of the detected magnetic vectors has become larger than a predetermined size. Therefore, it is possible to precisely calculate the center position, and it is thus possible to more precisely calculate the attitude.
(4)
The predetermined condition may be that directions of the detected magnetic vectors have been spread wider than a predetermined range.
With configuration (4) above, the center position is calculated when the directions of the detected magnetic vectors have been spread wider than a predetermined range. Therefore, it is possible to precisely calculate the center position, and it is thus possible to more precisely calculate the attitude.
(5)
In response to the predetermined condition, the computer may set an initial center position at a position on an inner side of the curved surface which is estimated based on the end point positions of the detected magnetic vectors.
With configuration (5) above, the initial center position is set at a position on the inner side of the curved surface. Thus, by updating the center position thereafter, the center position can be more reliably converged to an accurate position.
(6)
The computer may set an initial center position inside an area determined so as to include the end point positions of the detected magnetic vectors.
With configuration (6) above, the initial center position is set inside an area determined so as to include the end point positions of the detected magnetic vectors. Thus, by updating the center position thereafter, the center position can be brought gradually closer to the actual center position of the spherical body. With the configuration above, it is possible to reduce the possibility that the center position is set at a position so off that it is difficult to be brought closer to the actual center of the spherical body through updates, and it is possible to precisely estimate the center position.
(7)
The computer may set an initial center position inside a rectangular parallelepiped of a smallest size that includes the end point positions of the detected magnetic vectors.
With configuration (7) above, it is possible to easily set to initial center position inside the area determined so as to include the end point positions of the detected magnetic vectors.
(8)
The computer may set an initial center position at a centroid position among the end point positions of the detected magnetic vectors.
With configuration (8) above, the initial center position can be reliably set at a position on the inner side of the curved surface.
(9)
The computer may calculate the attitude of the input unit based on the direction vector at least on a condition that the predetermined condition is satisfied.
With configuration (9) above, it is possible to reduce the possibility that an inaccurate attitude is obtained using an inaccurate center position, and it is possible to more precisely calculate the attitude.
(10)
The computer may calculate the attitude while relatively decreasing an influence of a newly-obtained detected magnetic vector as an amount of change of the center position before and after an update is larger.
With configuration (10) above, the influence of the newly-obtained detected magnetic vector on the attitude calculation is decreased when the amount of change (the amount of movement) of the center position is large. Now, if the amount of change of the center position is large, it is believed that there is a possibility that the center position is inaccurate. Therefore, with configuration (10) above, it is possible to reduce the possibility that an inaccurate attitude is obtained using a center position that is possibly inaccurate, and it is therefore possible to precisely calculate the attitude.
(11)
The computer may calculate the attitude while relatively decreasing an influence of a newly-obtained detected magnetic vector as dispersion between lengths from a current center position to the end point positions of the detected magnetic vectors used for the estimation of the center position is larger.
With configuration (11) above, when the dispersion is large, the influence of a newly-obtained detected magnetic vector on the attitude calculation is small. Now, when the dispersion is large, it is believed that there is a possibility that the center position is inaccurate. Therefore, with configuration (11) above, it is possible to reduce the possibility that an inaccurate attitude is obtained using a center position that is possibly inaccurate, and it is therefore possible to precisely calculate the attitude.
Note that the present specification discloses an information processing device and an information processing system including various units that are equivalent to various units implemented by executing the information processing program recited in configurations (1) to (11) above. The present specification also discloses an attitude calculation method to be carried out in configurations (1) to (11).
With the storage medium having information processing program stored thereon, the information processing device, the information processing system and the attitude calculation method, the center position is updated each time a detected magnetic vector is obtained, whereby it is possible to more precisely calculate the attitude of the input unit.
These and other objects, features, aspects and advantages will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings.